package com.ruoyi.member.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.member.domain.MemberLevel;
import com.ruoyi.member.mapper.MemberLevelMapper;
import com.ruoyi.member.service.IMemberLevelService;

/**
 * 会员等级Service业务层处理
 * 
 * @author ruoyi
 */
@Service
public class MemberLevelServiceImpl implements IMemberLevelService {
    @Autowired
    private MemberLevelMapper memberLevelMapper;

    /**
     * 查询会员等级列表
     * 
     * @param memberLevel 会员等级信息
     * @return 会员等级集合
     */
    @Override
    public List<MemberLevel> selectMemberLevelList(MemberLevel memberLevel) {
        return memberLevelMapper.selectMemberLevelList(memberLevel);
    }

    /**
     * 查询所有会员等级
     * 
     * @return 会员等级列表
     */
    @Override
    public List<MemberLevel> selectMemberLevelAll() {
        return memberLevelMapper.selectMemberLevelAll();
    }

    /**
     * 通过等级ID查询会员等级
     * 
     * @param levelId 等级ID
     * @return 会员等级对象信息
     */
    @Override
    public MemberLevel selectMemberLevelById(Integer levelId) {
        return memberLevelMapper.selectMemberLevelById(levelId);
    }

    /**
     * 根据积分获取对应等级
     * 
     * @param points 积分
     * @return 会员等级对象信息
     */
    @Override
    public MemberLevel selectMemberLevelByPoints(Integer points) {
        return memberLevelMapper.selectMemberLevelByPoints(points);
    }

    /**
     * 新增会员等级
     * 
     * @param memberLevel 会员等级信息
     * @return 结果
     */
    @Override
    public int insertMemberLevel(MemberLevel memberLevel) {
        return memberLevelMapper.insertMemberLevel(memberLevel);
    }

    /**
     * 修改会员等级
     * 
     * @param memberLevel 会员等级信息
     * @return 结果
     */
    @Override
    public int updateMemberLevel(MemberLevel memberLevel) {
        return memberLevelMapper.updateMemberLevel(memberLevel);
    }

    /**
     * 修改会员等级状态
     * 
     * @param memberLevel 会员等级信息
     * @return 结果
     */
    @Override
    public int updateMemberLevelStatus(MemberLevel memberLevel) {
        return memberLevelMapper.updateMemberLevel(memberLevel);
    }

    /**
     * 校验等级名称是否唯一
     * 
     * @param memberLevel 会员等级信息
     * @return 结果
     */
    @Override
    public boolean checkLevelNameUnique(MemberLevel memberLevel) {
        Integer levelId = StringUtils.isNull(memberLevel.getLevelId()) ? -1 : memberLevel.getLevelId();
        MemberLevel info = memberLevelMapper.selectMemberLevelById(levelId);
        if (StringUtils.isNotNull(info) && info.getLevelName().equals(memberLevel.getLevelName())) {
            return false;
        }
        return memberLevelMapper.checkLevelNameUnique(memberLevel.getLevelName()) == 0;
    }

    /**
     * 校验等级值是否唯一
     * 
     * @param memberLevel 会员等级信息
     * @return 结果
     */
    @Override
    public boolean checkLevelValueUnique(MemberLevel memberLevel) {
        Integer levelId = StringUtils.isNull(memberLevel.getLevelId()) ? -1 : memberLevel.getLevelId();
        MemberLevel info = memberLevelMapper.selectMemberLevelById(levelId);
        if (StringUtils.isNotNull(info) && info.getLevelValue().equals(memberLevel.getLevelValue())) {
            return false;
        }
        return memberLevelMapper.checkLevelValueUnique(memberLevel.getLevelValue()) == 0;
    }

    /**
     * 删除会员等级信息
     * 
     * @param levelId 等级ID
     * @return 结果
     */
    @Override
    public int deleteMemberLevelById(Integer levelId) {
        return memberLevelMapper.deleteMemberLevelById(levelId);
    }

    /**
     * 批量删除会员等级信息
     * 
     * @param levelIds 需要删除的等级ID
     * @return 结果
     */
    @Override
    public int deleteMemberLevelByIds(Integer[] levelIds) {
        return memberLevelMapper.deleteMemberLevelByIds(levelIds);
    }
} 